package 牛客_面试必刷.Month07.day07;

public class 链表指定区间进行反转 {
    public ListNode reverseBetween (ListNode head, int m, int n) {
        ListNode res = new ListNode(0);//定义虚拟节点
        res.next = head;//指向头结点
        ListNode cur = head;
        ListNode pre = res;
        for (int i = 1; i < m; i++) {
            pre = cur;
            cur = cur.next;
        }
        for (int i = m; i < n; i++) {
            //这里的不是很懂
            ListNode temp = cur.next;
            cur.next = temp.next;
            temp.next = pre.next;
            pre.next = temp;
        }
        return res.next;
    }
}
